class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        if(temperatures.empty()) return {};

        vector <int> answer(temperatures.size(),0);
        int n = temperatures.size();
        stack  <int> index;


        for(int i = 0 ; i < n ; i++)
        {
            while(!index.empty() && temperatures[i] > temperatures[index.top()])
            {
                int cur_top_temperatures = index.top();
                index.pop();

                answer[cur_top_temperatures] = i - cur_top_temperatures;

            }
            index.push(i);
        }
        return answer;
    }
};








